package com.yanqu.road.server.cmd.system;

import com.yanqu.road.entity.log.LogGuide;
import com.yanqu.road.pb.guide.GuideProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.log.AutoLogMgr;
import com.yanqu.road.server.manger.log.LogMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.command.Cmd;

@Cmd(code = Protocol.S_GUIDE_LOG, desc = "记录引导")
public class GuideLogCmd extends AbstractCommand {

	private int eventId;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		GuideProto.GuideLogReqMsg reqMsg = GuideProto.GuideLogReqMsg.parseFrom(packet.getBytes());
		eventId = reqMsg.getEventId();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		AutoLogMgr.add(new LogGuide(player.getUserId(), eventId));
	}

	@Override
	public void sendData(GamePlayer player) {
		GuideProto.GuideLogRespMsg.Builder respMsg = GuideProto.GuideLogRespMsg.newBuilder();
		respMsg.setRet(0);
		player.sendPacket(Protocol.U_GUIDE_LOG, respMsg);
	}

}
